package lib.bone.admin.event;

import lib.bone.access.config.cycle.NepuCycleService;
import lib.bone.access.module.dict.DictServiceCtl;
import lib.bone.audit.flow.event.sub.*;
import lib.bone.flow.domain.dto.FlowParam;
import lib.bone.flow.domain.entity.FlowWork;
import lib.bone.flow.domain.model.EndModel;
import lib.bone.flow.event.FlowEndNodeEvent;
import lib.bone.nepudata.service.NepuTopicTaskService;
import lib.bone.nepudata.service.ResearchServiceCtl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author : kindear
 */

/**
 * @author ：贾斯淇
 */
@Slf4j
@Service
public class FlowEndNodeEventImpl implements FlowEndNodeEvent {

//    @Autowired
//    NepuResearchWorkloadService workloadService;

    @Autowired
    ResearchServiceCtl researchServiceCtl;

    @Autowired
    DictServiceCtl dictServiceCtl;

    @Autowired
    NepuTopicTaskService nepuTopicTaskService;


    @Autowired
    NepuCycleService nepuCycleService;

    @Autowired
    PaperEndEvent paperEndEvent;

    @Autowired
    AwardEndEvent awardEndEvent;

    @Autowired
    BookEndEvent bookEndEvent;

    @Autowired
    PropertyEndEvent propertyEndEvent;

    @Autowired
    SubjectEndEvent subjectEndEvent;

    @Autowired
    ThinkTankEndEvent thinkTankEndEvent;

    @Autowired
    TopicEndEvent topicEndEvent;

    @Override
    public void onEvent(FlowWork flowWork, EndModel endModel, FlowParam flowParam) {
        String serviceType = flowParam.getServiceType();
        String serviceId = flowParam.getServiceId();
        log.info("服务类型{},服务ID{}",serviceType,serviceId);
        switch (serviceType){
            case "论文":{
                paperEndEvent.process(flowWork,flowParam);
                break;
            }
            case "教学科研获奖":{
                awardEndEvent.process(flowWork,flowParam);
                break;
            }
            case "著作教材":{
                bookEndEvent.process(flowWork,flowParam);
                break;
            }
            case "知识产权":{
                propertyEndEvent.process(flowWork,flowParam);
                break;
            }
            case "横向课题":{
                subjectEndEvent.process(flowWork,flowParam);
                break;
            }
            case "智库类成果":{
                thinkTankEndEvent.process(flowWork,flowParam);
                break;
            }
            case "纵向课题":{
                topicEndEvent.process(flowWork,flowParam);
                break;
            }
        }
        //类型为论文条件:
//        if (serviceType.equals(ResearchTypeConst.PAPER)) {
//            // 1. 查询提交论文记录
//            Optional<Object> entityOp =  researchServiceCtl.getById(serviceId,ResearchTypeConst.PAPER);
//            if (!entityOp.isPresent()) throw new BusinessException(ResponseCodeConst.SYSTEM_ERROR);
//            NepuPaper paper = new NepuPaper();
//            BeanUtil.copyProperties(entityOp.get(),paper, CopyOptions.create().setIgnoreNullValue(true).setIgnoreError(true));
//            // 2. 获取工作量
//
//            String researchName=paper.getPaperTitle();
//            NepuPaperDict paperDict = (NepuPaperDict) dictServiceCtl.getById(paper.getPaperDictId(),ResearchTypeConst.PAPER).get();
//            String level = paperDict.getPaperLevel();
//            // 3. 如果为空或者不存在 则 从词典中获取
//            Integer workload = paper.getWorkload();
//            if (Validator.isEmpty(workload)) {
//                workload = paperDict.getWorkloadMax();
//            }
//            // 4. 获取获得工作量的人员身份
//            NepuResearchWorkload base = new NepuResearchWorkload();
//            Long userId = paper.getCorrespondingAuthorId();
//            base.setPlayRole("通讯作者");
//            if (!paper.getSecondAuthorId().equals(0L)) userId = paper.getSecondAuthorId();base.setPlayRole("第二作者");
//            if (!paper.getFirstAuthorId().equals(0L)) userId = paper.getFirstAuthorId();base.setPlayRole("第一作者");
//
//            base.setUserId(userId);
//            // 设置当前周期
//            base.setCycleId(paper.getCycleId());
//            base.setLevel(level);
//            base.setResearchName(researchName);
//            base.setResearchType(ResearchTypeConst.PAPER);
//            base.setMapperId(serviceId);
//            // 6. 配置消耗量为 0 用尽标识为-未用尽
//            base.setWorkload(workload);
//            base.setUsedWorkload(0);
//            base.setUsedUp(0);
//          //  base.setUserId(Long.parseLong(flowWork.getInitiator()));
//            // 7. 配置工作量为可分配
//            base.setDistributeAccess(1);
//            workloadService.saveOne(base);
            // 8. 第一作者学生 导师得全部工作量
//            if (paper.getFirstAuthorId().equals(0L)) {
//                NepuResearchWorkload extendWorkload = new NepuResearchWorkload();
//                BeanUtil.copyProperties(base, extendWorkload, CopyOptions.create().setIgnoreNullValue(true).setIgnoreError(true));
//                extendWorkload.setWorkload(workload);
//                // 根据导师身份定义确定 分配给谁工作量
//                if (paper.getTeacherIdentity().equals(1)) {
//                    extendWorkload.setPlayRole("第二作者");
//                    extendWorkload.setUserId(paper.getSecondAuthorId());
//                } else if (paper.getTeacherIdentity().equals(2)) {
//                    extendWorkload.setPlayRole("通讯作者");
//                    extendWorkload.setUserId(paper.getCorrespondingAuthorId());
//                }
//                workloads.add(extendWorkload);
//            }
//            // 9. 第一作者为职工得 70% 工作量 无指导教师 得 100%
//            else {
//                NepuResearchWorkload extendWorkload = new NepuResearchWorkload();
//                BeanUtil.copyProperties(base, extendWorkload, CopyOptions.create().setIgnoreNullValue(true).setIgnoreError(true));
////                Double tmp = workload * 0.3;
//                extendWorkload.setWorkload(workload);
//                if (paper.getTeacherIdentity().equals(1)) {
//                    extendWorkload.setPlayRole("第二作者");
//                    extendWorkload.setUserId(paper.getSecondAuthorId());
//                    workloads.add(extendWorkload);
//                } else if (paper.getTeacherIdentity().equals(2)) {
//                    extendWorkload.setPlayRole("通讯作者");
//                    extendWorkload.setUserId(paper.getCorrespondingAuthorId());
//                    workloads.add(extendWorkload);
//                }
//
//                NepuResearchWorkload self = new NepuResearchWorkload();
//                BeanUtil.copyProperties(base, self, CopyOptions.create().setIgnoreError(true).setIgnoreNullValue(true));
////                Double stmp = 0.0;
//                if (paper.getTeacherIdentity().equals(0)) {
////                    stmp = workload * 1.0;
////                }else {
////                    stmp = workload * 0.7;
////                }
//
//                    self.setPlayRole("第一作者");
//                    self.setUserId(paper.getFirstAuthorId());
//                    self.setWorkload(workload);
//                    workloads.add(self);
//                }
                //无指导教师，自己为第一作者，身份为职工
//                if (paper.getTeacherIdentity().equals(0) && !paper.getFirstAuthorId().equals(0L)) {
                //将第一作者职工工作量写入
//                    NepuResearchWorkload firstWorkload = new NepuResearchWorkload();
//                    BeanUtil.copyProperties(base, firstWorkload, CopyOptions.create().setIgnoreNullValue(true).setIgnoreError(true));
//                Double tmp = workload * 0.7;
//                Integer firstAuthorWorkload = tmp.intValue();
//                    firstWorkload.setPlayRole("第一作者");//负责人
//                    firstWorkload.setUserId(paper.getFirstAuthorId());//leadId
//                    firstWorkload.setWorkload(workload); // workload
//                    workloads.add(firstWorkload);
//                //将第二作者导师工作量写入
//                NepuResearchWorkload secondWorkload = new NepuResearchWorkload();
//                BeanUtil.copyProperties(base,secondWorkload, CopyOptions.create().setIgnoreNullValue(true).setIgnoreError(true));
//                Double stmp = workload * 0.3;
//                Integer secondAuthorWorkload  = stmp.intValue();
//                secondWorkload.setPlayRole("第二作者");
//                secondWorkload.setUserId(paper.getSecondAuthorId());
//                secondWorkload.setWorkload(secondAuthorWorkload);
//                workloads.add(secondWorkload);
//                } else if (paper.getFirstAuthorType().equals("学生")) {
//                // 二作导师得到全部工作量
//                NepuResearchWorkload secondWorkload = new NepuResearchWorkload();
//                BeanUtil.copyProperties(base,secondWorkload, CopyOptions.create().setIgnoreNullValue(true).setIgnoreError(true));
////                Integer secondAuthorWorkload  = stmp.intValue();
//                secondWorkload.setPlayRole("第二作者");
//                secondWorkload.setUserId(paper.getSecondAuthorId());
//                secondWorkload.setWorkload(workload);
//                workloads.add(secondWorkload);

//            }
            // 5. 写入工作量记录
            //workloadService.saveList(workloads);
//        }
//        else if(serviceType.equals(ResearchTypeConst.AWARD)){
//            //如果是教学科研奖励
//            // 1. 查询提交教学科研奖励记录
//            Optional<Object> nepuAwardOp =  researchServiceCtl.getById(serviceId,ResearchTypeConst.AWARD);
//            NepuAward award = new NepuAward();
//            BeanUtil.copyProperties(nepuAwardOp.get(),award, CopyOptions.create().setIgnoreNullValue(true).setIgnoreError(true));
//            // 2. 获取对应教学科研奖励词典获取工作量
//            Integer workload = award.getWorkload();
//            NepuAwardDict awardDict = (NepuAwardDict) dictServiceCtl.getById(award.getAwardDictId(),ResearchTypeConst.AWARD).get();
//            String level=awardDict.getAwardLevel();
//            String researchName=awardDict.getAwardName();
//            if (Validator.isEmpty(workload)){
//                workload = awardDict.getWorkloadMax();
//            }
//            // 3. 构建工作量写入列表
//            NepuResearchWorkload workloads = new NepuResearchWorkload();
//            // 4. 根据负责人身份构建
//            NepuResearchWorkload base = new NepuResearchWorkload();
//            base.setCycleId(award.getCycleId());
//            base.setUsedUp(0);
//            base.setUsedWorkload(0);
//            base.setResearchType(ResearchTypeConst.AWARD);
//            base.setMapperId(serviceId);
//            base.setLevel(level);
//            base.setResearchName(researchName);
//            // 5. 设置为可分配
//            base.setDistributeAccess(1);
//            // 6. 根据署名单位计算不同工作量
//            if (award.getSignatureGrade().equals("一")){
//                // 我校署名单位为一得到全部工作量
//                BeanUtil.copyProperties(base,workloads, CopyOptions.create().setIgnoreNullValue(true).setIgnoreError(true));
//                workloads.setPlayRole("负责人");
//                workloads.setUserId(award.getLeaderId());
//                workloads.setWorkload(workload);
//            } else if(award.getSignatureGrade().equals("二")){
//                // 我校署名单位为二得到全部工作量的40%
//                BeanUtil.copyProperties(base,workloads, CopyOptions.create().setIgnoreNullValue(true).setIgnoreError(true));
//                Double stmp = workload * 0.4;
//                Integer LeaderWorkload  = stmp.intValue();
//                workloads.setPlayRole("负责人");
//                workloads.setUserId(award.getLeaderId());
//                workloads.setWorkload(LeaderWorkload);
//            }
//            else if(award.getSignatureGrade().equals("三")){
//                // 我校署名单位为二得到全部工作量的20%
//                BeanUtil.copyProperties(base,workloads, CopyOptions.create().setIgnoreNullValue(true).setIgnoreError(true));
//                Double stmp = workload * 0.2;
//                Integer LeaderWorkload  = stmp.intValue();
//                workloads.setPlayRole("负责人");
//                workloads.setUserId(award.getLeaderId());
//                workloads.setWorkload(LeaderWorkload);
//            }
//            // 5. 写入工作量记录
//            workloadService.saveOne(workloads);
//        }else if(serviceType.equals(ResearchTypeConst.BOOK)){
//            // 1. 查询提交著作教材记录
//            Optional<Object> nepuBookOp =  researchServiceCtl.getById(serviceId,ResearchTypeConst.BOOK);
//            NepuBook book = new NepuBook();
//            BeanUtil.copyProperties(nepuBookOp.get(),book, CopyOptions.create().setIgnoreNullValue(true).setIgnoreError(true));
//            // 2. 获取对应著作教材词典获取工作量系数
//            NepuBookDict bookDict = (NepuBookDict) dictServiceCtl.getById(book.getBookDictId(),ResearchTypeConst.BOOK).get();
//            String level=bookDict.getBookLevel();
//            Integer workloadStandard = bookDict.getWorkloadStandard();
//            String researchName=book.getBookName();
//            //获取著作教材中字数
//            double wordsNumber = book.getWordsNumber();
//            // 3. 构建工作量写入
//            NepuResearchWorkload workloads = new NepuResearchWorkload();
//            // 4. 根据负责人身份构建
//            NepuResearchWorkload base = new NepuResearchWorkload();
//            base.setCycleId(book.getCycleId());
//            base.setUsedUp(0);
//            base.setUsedWorkload(0);
//            base.setResearchType(ResearchTypeConst.BOOK);
//            base.setMapperId(serviceId);
//            base.setLevel(level);
//            base.setResearchName(researchName);
//            // 5. 设置为可分配
//            base.setDistributeAccess(1);
//            // 第一作者得全部工作量，可以用于分配
//            BeanUtil.copyProperties(base,workloads, CopyOptions.create().setIgnoreNullValue(true).setIgnoreError(true));
//            Double stmp = wordsNumber * workloadStandard;
//            Integer workload = book.getWorkload();
//             if (Validator.isEmpty(workload)){
//                 workload  = stmp.intValue();
//             }
//            workloads.setPlayRole("第一作者");
//            workloads.setUserId(book.getFirstAuthorId());
//            workloads.setWorkload(workload);
//            // 5. 写入工作量记录
//            workloadService.saveOne(workloads);
//        }else if(serviceType.equals(ResearchTypeConst.PROPERTY)){
//            //如果是知识产权
//            // 1. 查询提交知识产权记录
//            Optional<Object> nepuPropertyOp =  researchServiceCtl.getById(serviceId,ResearchTypeConst.PROPERTY);
//            NepuProperty property = new NepuProperty();
//            BeanUtil.copyProperties(nepuPropertyOp.get(),property, CopyOptions.create().setIgnoreNullValue(true).setIgnoreError(true));
//            // 2. 获取对应知识产权词典获取工作量
//            NepuPropertyDict propertyDict = (NepuPropertyDict) dictServiceCtl.getById(property.getPropertyDictId(),ResearchTypeConst.PROPERTY).get();
//            String level=propertyDict.getPropertyLevel();
//            Integer workload = property.getWorkload();
//            String researchName=property.getPropertyName();
//            if (Validator.isEmpty(workload)){
//                workload = propertyDict.getWorkloadMax();
//            }
//            // 3. 构建工作量写入
//            NepuResearchWorkload workloads = new NepuResearchWorkload();
//            // 4. 根据第一作者身份构建
//            NepuResearchWorkload base = new NepuResearchWorkload();
//            base.setCycleId(property.getCycleId());
//            base.setUsedUp(0);
//            base.setUsedWorkload(0);
//            base.setResearchType(ResearchTypeConst.PROPERTY);
//            base.setMapperId(serviceId);
//            base.setLevel(level);
//            base.setResearchName(researchName);
//            // 5. 设置为可分配
//            base.setDistributeAccess(0);
//            if (property.getFirstAuthorId().equals(0L)){
//                // 知识产权第一完成人为学生，第二完成人为指导教师，则工作量按50%核算
//                BeanUtil.copyProperties(base,workloads, CopyOptions.create().setIgnoreNullValue(true).setIgnoreError(true));
//                double stmp = workload * 0.5;
//                Integer secondWorkLoad = (int) stmp;
//                workloads.setPlayRole("第二完成人");
//                workloads.setUserId(property.getSecondAuthorId());
//                workloads.setWorkload(secondWorkLoad);
//            }else{
//                //我校为第一知识产权拥有单位，知识产权成果工作量只核算第一完成人（职工）
//                BeanUtil.copyProperties(base,workloads, CopyOptions.create().setIgnoreNullValue(true).setIgnoreError(true));
//                workloads.setPlayRole("第一完成人");
//                workloads.setUserId(property.getFirstAuthorId());
//                workloads.setWorkload(workload);
//            }
//            // 5. 写入工作量记录
//            workloadService.saveOne(workloads);
//        }else if(serviceType.equals(ResearchTypeConst.SUBJECT)){
//            //如果是横向课题
//            // 1. 查询提交横向课题记录
//            Optional<Object> nepuSubjectOp =  researchServiceCtl.getById(serviceId,ResearchTypeConst.SUBJECT);
//            NepuSubject subject = new NepuSubject();
//            BeanUtil.copyProperties(nepuSubjectOp.get(),subject, CopyOptions.create().setIgnoreNullValue(true).setIgnoreError(true));
//            // 2. 获取对应横向课题词典获取工作量系数
//            NepuSubjectDict subjectDict = (NepuSubjectDict) dictServiceCtl.getById(subject.getSubjectDictId(),ResearchTypeConst.SUBJECT).get();
//            String level=subjectDict.getSubjectLevel();
//            Integer workload = subject.getWorkload();
//            String researchName=subject.getSubjectName();
//            if (Validator.isEmpty(workload)){
//                workload = subjectDict.getWorkloadMax();
//            }
//
//            // 3. 构建工作量写入
//            NepuResearchWorkload workloads = new NepuResearchWorkload();
//            // 4. 根据负责人身份构建
//            NepuResearchWorkload base = new NepuResearchWorkload();
//            base.setCycleId(subject.getCycleId());
//            base.setUsedUp(0);
//            base.setUsedWorkload(0);
//            base.setResearchType(ResearchTypeConst.SUBJECT);
//            base.setMapperId(serviceId);
//            base.setLevel(level);
//            base.setResearchName(researchName);
//            // 5. 设置为可分配
//            base.setDistributeAccess(1);
//            BeanUtil.copyProperties(base,workloads, CopyOptions.create().setIgnoreNullValue(true).setIgnoreError(true));
//            workloads.setPlayRole("负责人");
//            workloads.setUserId(subject.getLeaderId());
//            workloads.setWorkload(workload);
//            // 5. 写入工作量记录
//            workloadService.saveOne(workloads);
//        }else if(serviceType.equals(ResearchTypeConst.THINKTANK)){
//            //如果是智库类成果
//            // 1. 查询提交智库类成果记录
//            Optional<Object> nepuThinkTankOp =  researchServiceCtl.getById(serviceId,ResearchTypeConst.THINKTANK);
//            NepuThinkTank thinkTank = new NepuThinkTank();
//            BeanUtil.copyProperties(nepuThinkTankOp.get(),thinkTank, CopyOptions.create().setIgnoreNullValue(true).setIgnoreError(true));
//            // 2. 获取对应智库类成果词典获取工作量
//            NepuThinkTankDict thinkTankDict = (NepuThinkTankDict) dictServiceCtl.getById(thinkTank.getThinktankDictId(),ResearchTypeConst.THINKTANK).get();
//            String level=thinkTankDict.getThinktankLevel();
//            Integer workload = thinkTank.getWorkload();
//            String researchName=thinkTank.getName();
//            if (Validator.isEmpty(workload)){
//                workload = thinkTankDict.getWorkloadMax();
//            }
//            //Integer workload = thinkTankDict.getWorkloadMax();
//            // 3. 构建工作量写入列表
//            NepuResearchWorkload workloads = new NepuResearchWorkload();
//            // 4. 根据负责人身份构建
//            NepuResearchWorkload base = new NepuResearchWorkload();
//            base.setCycleId(thinkTank.getCycleId());
//            base.setLevel(level);
//            base.setResearchName(researchName);
//            base.setResearchType(ResearchTypeConst.THINKTANK);
//            base.setMapperId(serviceId);
//            base.setUsedUp(0);
//            base.setUsedWorkload(0);
//            // 5. 设置为不可分配
//            base.setDistributeAccess(0);
//            if (thinkTank.getSignatureGrade().equals("一")){
//                // 我校署名单位为一得到全部工作量
//                BeanUtil.copyProperties(base,workloads, CopyOptions.create().setIgnoreNullValue(true).setIgnoreError(true));
//                workloads.setPlayRole("负责人");//第一作者
//                workloads.setUserId(thinkTank.getLeaderId());
//                workloads.setWorkload(workload);
//            } else if(thinkTank.getSignatureGrade().equals("二")){
//                // 我校署名单位为二得到全部工作量的40%
//                BeanUtil.copyProperties(base,workloads, CopyOptions.create().setIgnoreNullValue(true).setIgnoreError(true));
//                Double stmp = workload * 0.4;
//                Integer LeaderWorkload  = stmp.intValue();
//                workloads.setPlayRole("负责人");
//                workloads.setUserId(thinkTank.getLeaderId());
//                workloads.setWorkload(LeaderWorkload);
//            }
//            else if(thinkTank.getSignatureGrade().equals("三")){
//                // 我校署名单位为二得到全部工作量的20%
//                BeanUtil.copyProperties(base,workloads, CopyOptions.create().setIgnoreNullValue(true).setIgnoreError(true));
//                Double stmp = workload * 0.2;
//                Integer LeaderWorkload  = stmp.intValue();
//                workloads.setPlayRole("负责人");
//                workloads.setUserId(thinkTank.getLeaderId());
//                workloads.setWorkload(LeaderWorkload);
//            }
//            // 5. 写入工作量记录
//            workloadService.saveOne(workloads);
//        }
//        else if (serviceType.equals(ResearchTypeConst.TOPIC)){
//            //如果是纵向课题
//            // 1. 查询提交纵向课题记录
//            Optional<Object> nepuTopicOp =  researchServiceCtl.getById(serviceId,ResearchTypeConst.TOPIC);
//            NepuTopic topic = new NepuTopic();
//            BeanUtil.copyProperties(nepuTopicOp.get(),topic, CopyOptions.create().setIgnoreNullValue(true).setIgnoreError(true));
//            // 2. 获取对应纵向课题词典获取工作量系数
//            NepuTopicDict topicDict = (NepuTopicDict) dictServiceCtl.getById(topic.getTopicDictId(),ResearchTypeConst.TOPIC).get();
//            String level=topicDict.getTopicLevel();
//            //按照最大的计算 - -
//            String cycleId = nepuCycleService.getNowCycleId();
//            Optional<NepuCycle> nepuCycleOp = nepuCycleService.getById(cycleId);
//            NepuCycle nepuCycle = new NepuCycle();
//            if (Validator.isNotEmpty(nepuCycleOp)){
//                BeanUtil.copyProperties(nepuCycleOp.get(),nepuCycle,CopyOptions.create().setIgnoreNullValue(true).setIgnoreError(true));
//            }
//            Date buildDate;
//            Date endDate;
//            if (topic.getBuildDate().compareTo(nepuCycle.getStartDate())==-1||
//                    topic.getBuildDate().compareTo(nepuCycle.getStartDate())==0){
//                buildDate = nepuCycle.getStartDate();
//            }else{
//                buildDate = topic.getBuildDate();
//
//            }
//            if (topic.getEndDate().compareTo(nepuCycle.getEndDate())==-1||
//                    topic.getBuildDate().compareTo(nepuCycle.getStartDate())==0){
//                endDate = topic.getEndDate();
//            }else{
//                endDate = nepuCycle.getEndDate();
//
//            }
//            System.out.println("endDate"+endDate);
//            System.out.println("buildDate"+buildDate);
//            long betweenDay = DateUtil.between(buildDate,endDate, DateUnit.DAY);
//            System.out.println("betweenDay"+betweenDay);
//            int monthCount = (int) (betweenDay/30 + 1);
//
//            Integer monthworkload = topicDict.getWorkloadMax()/12+(topicDict.getWorkloadMax()%12!=0?1:0);
//            Integer workload = monthworkload*monthCount;
//
//            String researchName=topic.getTopicName();
//
//           // Integer workload = topicDict.getWorkloadMax();
//            // 3. 构建工作量写入
//            NepuResearchWorkload workloads = new NepuResearchWorkload();
//            // 4. 根据负责人身份构建
//            NepuResearchWorkload base = new NepuResearchWorkload();
//            base.setCycleId(topic.getCycleId());
//            base.setLevel(level);
//            base.setResearchName(researchName);
//            base.setResearchType(ResearchTypeConst.TOPIC);
//            base.setMapperId(serviceId);
//            base.setUsedUp(0);
//            base.setUsedWorkload(0);
//            // 5. 设置为可分配
//            base.setDistributeAccess(1);
//            BeanUtil.copyProperties(base,workloads, CopyOptions.create().setIgnoreNullValue(true).setIgnoreError(true));
//            workloads.setPlayRole("负责人");
//            workloads.setUserId(topic.getLeaderId());
//            // 6. 纵向课题总工作量计算
//
//            workloads.setWorkload(workload);
//            System.out.println("workload"+workload);
//            // 6. 写入数据库记录
//            workloadService.saveOne(workloads);
//            /**
//             * 假定为审核通过就发放第一年工作量
//             */
////            List<NepuTopicTask> tasks = new ArrayList<>();
////            Integer yearLen = topic.getYear();
////            for(int i=0;i<yearLen;i++){
////                NepuTopicTask task = new NepuTopicTask();
////                // 计算时间偏移量
////                Date releaseData = DateUtil.offset(topic.getStartDate(), DateField.YEAR, i);
////                task.setReleaseDate(releaseData);
////                task.setTopicId(topic.getId());
////                task.setWorkload(workload);
////                task.setStatus(1);
////                tasks.add(task);
////            }
////            // 5. 写入工作量记录
////            nepuTopicTaskService.saveList(tasks);
//        }
    }
}
